package DomainLayer;
import java.util.ArrayList;


public class CustomerCollection 
{
    private ArrayList<Customer> customers;
    private static CustomerCollection instance;

    private CustomerCollection()
    {
        customers= new ArrayList<Customer>();
    }
    
    //return only one object of class CustomerCollection
    public static CustomerCollection getInstance()
    {
                if(null== instance)
        {
            instance=new CustomerCollection();
        }
        return instance;
    }
    
    public void addCustomer(int id, String name, String address, String city)
    {
        Customer customer= new Customer(id, name, address, city);
        customers.add(customer);
    }
    
    
    public Customer searchCustomer(int id)
    {
        for (Customer customer:customers)
        {
            if (customer.getID()==id)
            return customer;
        }
        return null;
    }
    
    public void deleteCustomer(int id)
    {
        if(searchCustomer(id)==null)
        {
            throw new NullPointerException();
        }
        else
        customers.remove(searchCustomer(id));
        
    }
    
    //return string a list of all registered customers.
    public String printAllCustomers()
    {String s="";
        for (Customer customer: customers)
        {
            s+=customer.toString()+'\n';
        }
        return s;
    }
}
